package com.springboot.middleware.middleware_rabbitmq_logforlogin.server.service;

import com.springboot.middleware.middleware_rabbitmq_logforlogin.model.entity.User;
import com.springboot.middleware.middleware_rabbitmq_logforlogin.model.mapper.UserMapper;
import com.springboot.middleware.middleware_rabbitmq_logforlogin.server.dto.UserLoginDto;
import com.springboot.middleware.middleware_rabbitmq_logforlogin.server.publisher.LogPublisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private LogPublisher logPublisher;

    @Override
    public Boolean login(UserLoginDto dto) throws Exception {
        User user = userMapper.selectByUserNamePassword(dto.getUserName(), dto.getPassword());
        if (user != null) {
            dto.setUserId(user.getId());
            logPublisher.sendLogMsg(dto);
            return true;
        }
        return false;
    }
}
